﻿using Common;
using DevExpress.XtraEditors;
using DLL;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Linq;

namespace NursingFormSystem.InfantBaby
{
    public partial class InfantProducAfterEdit : Form
    {
        NursingFormRecord record = new NursingFormRecord();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        PatientInfo PatientInfo;
        Tb_User LoginUser;
        string Id;
        public InfantProducAfterEdit(Tb_User loginUser, PatientInfo patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = patientInfo;
            this.LoginUser = loginUser;
            BindInfo(this.Id);
        }
        public InfantProducAfterEdit(string[] loginUser, string[] patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = ArrayToObject.ArrayToPatientInfo(patientInfo);
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);
            BindInfo(this.Id);
        }

        void txtKaiNaiShiJian_DoubleClick(object sender, EventArgs e)
        {
            txtKaiNaiShiJian.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
        }

        void rdosTERGNJP_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtTergnjpText.Visible = true;
            if (rdosTERGNJP.SelectedIndex == 0)
            {
                txtTergnjpText.Visible = false;
                txtTergnjpText.Text = string.Empty;
            }
        }

        void rdosZhiChan_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtZhiChanText.Visible = true;
            if (rdosZhiChan.SelectedIndex == 0)
            {
                txtZhiChanText.Visible = false;
                txtZhiChanText.Text = string.Empty;
            }
        }

        void chkRshbz20_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRshbz20.Checked)
            {
                txtQitaNwkJb.Visible = true;
            }
            else
            {
                txtQitaNwkJb.Visible = false;
                txtQitaNwkJb.Text = string.Empty;
            }
        }
        private void chkBingfaZheng16_CheckedChanged(object sender, EventArgs e)
        {
            if (chkBingfaZheng16.Checked)
            {
                txtBingFaZheng.Visible = true;
            }
            else
            {
                txtBingFaZheng.Visible = false;
                txtBingFaZheng.Text = string.Empty;
            }
        }

        void txtZongPingFenShu4_Click(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtZongPingFenShu4.Text)) return;
            double sum = 0;
            if (!string.IsNullOrEmpty(txtMfzxinLv4.Text) && Regex.IsMatch(txtMfzxinLv4.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtMfzxinLv4.Text);
            if (!string.IsNullOrEmpty(txtHuxi4.Text) && Regex.IsMatch(txtHuxi4.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHuxi4.Text);
            if (!string.IsNullOrEmpty(txtJiZhangLi4.Text) && Regex.IsMatch(txtJiZhangLi4.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtJiZhangLi4.Text);
            if (!string.IsNullOrEmpty(txtHouFanShe4.Text) && Regex.IsMatch(txtHouFanShe4.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHouFanShe4.Text);
            if (!string.IsNullOrEmpty(txtPiFuYanSe4.Text) && Regex.IsMatch(txtPiFuYanSe4.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtPiFuYanSe4.Text);
            txtZongPingFenShu4.Text = sum.ToString();
        }
        void txtZongPingFenShu5_Click(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtZongPingFenShu5.Text)) return;
            double sum = 0;
            if (!string.IsNullOrEmpty(txtMfzxinLv5.Text) && Regex.IsMatch(txtMfzxinLv5.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtMfzxinLv5.Text);
            if (!string.IsNullOrEmpty(txtHuxi5.Text) && Regex.IsMatch(txtHuxi5.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHuxi5.Text);
            if (!string.IsNullOrEmpty(txtJiZhangLi5.Text) && Regex.IsMatch(txtJiZhangLi5.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtJiZhangLi5.Text);
            if (!string.IsNullOrEmpty(txtHouFanShe5.Text) && Regex.IsMatch(txtHouFanShe5.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHouFanShe5.Text);
            if (!string.IsNullOrEmpty(txtPiFuYanSe5.Text) && Regex.IsMatch(txtPiFuYanSe5.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtPiFuYanSe5.Text);
            txtZongPingFenShu5.Text = sum.ToString();
        }
        void txtZongPingFenShu6_Click(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtZongPingFenShu6.Text)) return;
            double sum = 0;
            if (!string.IsNullOrEmpty(txtMfzxinLv6.Text) && Regex.IsMatch(txtMfzxinLv6.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtMfzxinLv6.Text);
            if (!string.IsNullOrEmpty(txtHuxi6.Text) && Regex.IsMatch(txtHuxi6.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHuxi6.Text);
            if (!string.IsNullOrEmpty(txtJiZhangLi6.Text) && Regex.IsMatch(txtJiZhangLi6.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtJiZhangLi6.Text);
            if (!string.IsNullOrEmpty(txtHouFanShe6.Text) && Regex.IsMatch(txtHouFanShe6.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtHouFanShe6.Text);
            if (!string.IsNullOrEmpty(txtPiFuYanSe6.Text) && Regex.IsMatch(txtPiFuYanSe6.Text, @"^(0|([1-9]\d*))(\.\d+)?$"))
                sum += Convert.ToSingle(txtPiFuYanSe6.Text);
            txtZongPingFenShu6.Text = sum.ToString();
        }



        #region 保存
        private void simplebaocun_Click(object sender, EventArgs e)
        {
            InfantProducAfter ift = new InfantProducAfter();
            ift.ChanCi = txtChanCi.Text;
            ift.XingBie = ddlSex.Text;
            ift.RenShenZhouShu = txtRenShenZhouShu.Text;
            ift.ChuShengShiJian = txtChuShengShiJian.Text;
            ift.TaiWei = txtTaiWei.Text;
            ift.FenMianFangShi = ddlFenMianFangshi.Text;
            ift.TiZhong = txtTiZhong.Text;
            ift.ShenChang = txtShenChang.Text;
            ift.RenShenHeBingZheng = (chkRshbz1.Checked ? 1 : 0) + "#" + (chkRshbz2.Checked ? 1 : 0) + "#" + (chkRshbz3.Checked ? 1 : 0) + "#" + (chkRshbz4.Checked ? 1 : 0) + "#" +
                (chkRshbz5.Checked ? 1 : 0) + "#" + (chkRshbz6.Checked ? 1 : 0) + "#" + (chkRshbz7.Checked ? 1 : 0) + "#" + (chkRshbz8.Checked ? 1 : 0) + "#" +
                (chkRshbz9.Checked ? 1 : 0) + "#" + (chkRshbz10.Checked ? 1 : 0) + "#" + (chkRshbz11.Checked ? 1 : 0) + "#" + (chkRshbz12.Checked ? 1 : 0) + "#" +
                (chkRshbz13.Checked ? 1 : 0) + "#" + (chkRshbz14.Checked ? 1 : 0) + "#" + (chkRshbz15.Checked ? 1 : 0) + "#" + (chkRshbz16.Checked ? 1 : 0) + "#" +
                (chkRshbz17.Checked ? 1 : 0) + "#" + (chkRshbz18.Checked ? 1 : 0) + "#" + (chkRshbz19.Checked ? 1 : 0) + "#" + (chkRshbz20.Checked ? 1 : 0);
            ift.QiTaNeiWaiKeJiBing = txtQitaNwkJb.Text;

            ift.BingFaZhengChks = (chkBingfaZheng1.Checked ? 1 : 0) + "#" + (chkBingfaZheng2.Checked ? 1 : 0) + "#" + (chkBingfaZheng3.Checked ? 1 : 0) + "#" + (chkBingfaZheng4.Checked ? 1 : 0)
                + "#" + (chkBingfaZheng5.Checked ? 1 : 0) + "#" + (chkBingfaZheng6.Checked ? 1 : 0) + "#" + (chkBingfaZheng7.Checked ? 1 : 0) + "#" + (chkBingfaZheng8.Checked ? 1 : 0)
                + "#" + (chkBingfaZheng9.Checked ? 1 : 0) + "#" + (chkBingfaZheng10.Checked ? 1 : 0) + "#" + (chkBingfaZheng11.Checked ? 1 : 0) + "#" + (chkBingfaZheng12.Checked ? 1 : 0)
                + "#" + (chkBingfaZheng13.Checked ? 1 : 0) + "#" + (chkBingfaZheng14.Checked ? 1 : 0) + "#" + (chkBingfaZheng15.Checked ? 1 : 0) + "#" + (chkBingfaZheng16.Checked ? 1 : 0)
                + "#" + (chkBingfaZheng17.Checked ? 1 : 0) + "#" + (chkBingfaZheng18.Checked ? 1 : 0) + "#" + (chkBingfaZheng19.Checked ? 1 : 0) + "#" + (chkBingfaZheng20.Checked ? 1 : 0)
                + "#" + (chkBingfaZheng21.Checked ? 1 : 0) + "#" + (chkBingfaZheng22.Checked ? 1 : 0) + "#" + (chkBingfaZheng23.Checked ? 1 : 0) + "#" + (chkBingfaZheng24.Checked ? 1 : 0);

            ift.BingFaZheng = txtBingFaZheng.Text;
            ift.HBsAg = ddlHBsAg.Text;
            ift.ZaoPoShui = rdosZaoPoShui.SelectedIndex.ToString();
            ift.YangShui = ddlYangShui.Text;
            ift.GanRan = rdosGanRan.SelectedIndex.ToString();
            ift.ZhiChan = rdosZhiChan.SelectedIndex.ToString();
            ift.ZhiChanText = txtZhiChanText.Text;
            ift.TaiPanYiChang = rdosTaiPanYiChang.SelectedIndex.ToString();
            ift.TaiErGongNeiJiongPo = rdosTERGNJP.SelectedIndex.ToString();
            ift.TaiErGongNeiJiongPoText = txtTergnjpText.Text;
            ift.QiDaiYiChang = rdosQiDaiYiChang.SelectedIndex.ToString();
            ift.KaiNaiShiJian = txtKaiNaiShiJian.Text;

            //ift.MeiFenZhongXinLv1 = txtMfzxinLv1.Text;
            //ift.MeiFenZhongXinLv2 = txtMfzxinLv2.Text;
            //ift.MeiFenZhongXinLv3 = txtMfzxinLv3.Text;
            ift.MeiFenZhongXinLv4 = txtMfzxinLv4.Text;
            ift.MeiFenZhongXinLv5 = txtMfzxinLv5.Text;
            ift.MeiFenZhongXinLv6 = txtMfzxinLv6.Text;

            //ift.HuXi1 = txtHuxi1.Text;
            //ift.HuXi2 = txtHuxi2.Text;
            //ift.HuXi3 = txtHuxi3.Text;
            ift.HuXi4 = txtHuxi4.Text;
            ift.HuXi5 = txtHuxi5.Text;
            ift.HuXi6 = txtHuxi6.Text;

            //ift.JiZhangLi1 = txtJiZhangLi1.Text;
            //ift.JiZhangLi2 = txtJiZhangLi2.Text;
            //ift.JiZhangLi3 = txtJiZhangLi3.Text;
            ift.JiZhangLi4 = txtJiZhangLi4.Text;
            ift.JiZhangLi5 = txtJiZhangLi5.Text;
            ift.JiZhangLi6 = txtJiZhangLi6.Text;

            //ift.HouFanShe1 = txtHouFanShe1.Text;
            //ift.HouFanShe2 = txtHouFanShe2.Text;
            //ift.HouFanShe3 = txtHouFanShe3.Text;
            ift.HouFanShe4 = txtHouFanShe4.Text;
            ift.HouFanShe5 = txtHouFanShe5.Text;
            ift.HouFanShe6 = txtHouFanShe6.Text;

            //ift.PiFuYanSe1 = txtPiFuYanSe1.Text;
            //ift.PiFuYanSe2 = txtPiFuYanSe2.Text;
            //ift.PiFuYanSe3 = txtPiFuYanSe3.Text;
            ift.PiFuYanSe4 = txtPiFuYanSe4.Text;
            ift.PiFuYanSe5 = txtPiFuYanSe5.Text;
            ift.PiFuYanSe6 = txtPiFuYanSe6.Text;

            //ift.ZongPingFenShu1 = txtZongPingFenShu1.Text;
            //ift.ZongPingFenShu2 = txtZongPingFenShu2.Text;
            //ift.ZongPingFenShu3 = txtZongPingFenShu3.Text;
            ift.ZongPingFenShu4 = txtZongPingFenShu4.Text;
            ift.ZongPingFenShu5 = txtZongPingFenShu5.Text;
            ift.ZongPingFenShu6 = txtZongPingFenShu6.Text;

            ift.JieShengZhe = txtJieShengZhe.Text;
            if (string.IsNullOrEmpty(this.Id))
            {
                ift.DianYanZheId = LoginUser.UserId;
                ift.DianYanZhe = LoginUser.UserName;
            }
            else
            {
                ift.DianYanZheId = LoginUser.UserId;
                ift.DianYanZhe = txtDianYanZhe.Text;
            }
            //ift.TiWen = txtTiWen.Text;
            //ift.PiFu = txtPiFu.Text;
            //ift.TouBu = txtTouBu.Text;
            //ift.XiongBu = txtXiongBu.Text;
            //ift.FuBu = txtFuBu.Text;
            //ift.SiZhiZhangLi = txtSiZhiZhangLi.Text;
            //ift.ChuBuYinXiang = txtChuBuYinXiang.Text;
            //ift.JianChaZhe = txtJianChaZhe.Text;
            //ift.ZhiLiaoJingGuo = txtZhiLiaoJingGuo.Text;
            //ift.YiSheng = txtYiSheng.Text;
            //ift.ChuYuanJianCha = txtChuYuanJianCha.Text;
            //ift.ChuYuanZhenDuan = txtChuYuanZhenDuan.Text;
            //ift.ZhiLiaoZhuanGui = txtZhiLiaoZhuanGui.Text;
            //ift.ChuYuanYiZhu = txtChuYuanYiZhu.Text;
            //ift.ChuYuanRiQi = txtChuYuanRiQi.Text;


            ift.FormId = (int)FormType.FetationAfter;
            ift.FormName = EnumHelper.GetDescription(FormType.FetationAfter);
            record.NursingFormData = XmlUtil.ObjectToXML(ift, Encoding.UTF8);
            record.FormId = ift.FormId;//表单ID
            record.FormName = ift.FormName;//表单NAME
            record.PatientId = PatientInfo.PATIENT_ID;//住院号
            record.VisitId = PatientInfo.VISIT_ID;//住院次数
            record.PatientName = PatientInfo.PATIENT_NAME;//患者名称
            record.BedNo = PatientInfo.BED_NO;//床号
            record.DepartmentId = PatientInfo.DEPARTMENT_ID;//科室号
            record.DepartmentName = PatientInfo.DEPARTMENT_NAME;//科室名称
            record.AreaId = PatientInfo.NURSE_CELL_CODE;//病区编号
            record.AreaName = PatientInfo.NURSE_CELL_NAME;//病区名称
            record.AssessmentDate = DateTime.Now;//日期       

            record.Id = Id == "" ? 0 : Convert.ToInt32(Id);
            var ret = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));

            if (ret.Code == 1)
            {
                //电签开始
                if (Base.ESSwitch.Equals("on"))
                {
                    string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>{0}</sign_sys><title>{1}</title><patient_id>{2}</patient_id><patient_name>{3}</patient_name><emr_id>{4}</emr_id><emr_catalog>{5}</emr_catalog><his_id>{6}</his_id><event_no>{7}</event_no><visit_number>{8}</visit_number><dept_name>{9}</dept_name><prescribe_number>{10}</prescribe_number><prescribe_sub_number>{11}</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                    extraInfo = string.Format(extraInfo, EnumHelper.GetDescription(FormType.FetationAfter) + (record.Id > 0 ? "-更新" : "-新增"), EnumHelper.GetDescription(FormType.FetationAfter), record.PatientId, record.PatientName, record.Id, record.FormId, "", record.PatientId, record.VisitId, LoginUser.DepartmentName, record.PatientId, record.PatientId);
                    ElectronicSignature es = new ElectronicSignature(LoginUser);
                    bool res = es.GetElectronicSignatureImage(es, record.NursingFormData, extraInfo, ((int)FormType.FetationAfter).ToString(), EnumHelper.GetDescription(FormType.FetationAfter), PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID);
                    if (!res) { MessageBox.Show("电子签名失败"); return; }
                }
                MessageBox.Show(record.Id == 0 ? "新增成功" : "更新成功");
                if (record.Id > 0) return;
                //新增成功后绑定数据
                this.Id = string.Empty;
                BindInfo(this.Id);
            }
            else
            {
                MessageBox.Show(ret.M);
            }
            this.DialogResult = DialogResult.OK;
        }
        #endregion

        #region 打印
        private void simplequxiao_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Id)) { MessageBox.Show("请先保存"); return; }
            InfantProducAfterPrint f = new InfantProducAfterPrint(LoginUser, PatientInfo, this.Id);
            f.ShowDialog();
        }
        #endregion

        private void BindInfo(string id)
        {
            this.txtPatientName.Text = PatientInfo.PATIENT_NAME;
            this.txtBedName.Text = PatientInfo.BED_NO;
            this.txtPatientId.Text = PatientInfo.PATIENT_ID;
            this.txtDianYanZhe.Text = LoginUser.UserId;

            var ret = formService.GetNursingFormRecord(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.FetationAfter);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                list = list.OrderByDescending(p => p.AssessmentDate).ToList();
                NursingFormRecord record = null;
                if (string.IsNullOrEmpty(this.Id))
                    record = list[0];
                else
                    record = list.Find(p => p.Id == Convert.ToInt32(this.Id));
                this.Id = record.Id.ToString();
                var NursingFormData = record.NursingFormData;
                InfantProducAfter ift = new InfantProducAfter();
                ift = XmlUtil.XMLToObject<InfantProducAfter>(NursingFormData, Encoding.UTF8);
                txtChanCi.Text = ift.ChanCi;
                ddlSex.Text = ift.XingBie;
                txtRenShenZhouShu.Text = ift.RenShenZhouShu;
                txtChuShengShiJian.Text = ift.ChuShengShiJian;
                txtTaiWei.Text = ift.TaiWei;
                ddlFenMianFangshi.Text = ift.FenMianFangShi;
                txtTiZhong.Text = ift.TiZhong;
                txtShenChang.Text = ift.ShenChang;
                if (!string.IsNullOrEmpty(ift.RenShenHeBingZheng))
                {
                    chkRshbz1.Checked = ift.RenShenHeBingZheng.Split('#')[0].Equals("1");
                    chkRshbz2.Checked = ift.RenShenHeBingZheng.Split('#')[1].Equals("1");
                    chkRshbz3.Checked = ift.RenShenHeBingZheng.Split('#')[2].Equals("1");
                    chkRshbz4.Checked = ift.RenShenHeBingZheng.Split('#')[3].Equals("1");
                    chkRshbz5.Checked = ift.RenShenHeBingZheng.Split('#')[4].Equals("1");
                    chkRshbz6.Checked = ift.RenShenHeBingZheng.Split('#')[5].Equals("1");
                    chkRshbz7.Checked = ift.RenShenHeBingZheng.Split('#')[6].Equals("1");
                    chkRshbz8.Checked = ift.RenShenHeBingZheng.Split('#')[7].Equals("1");
                    chkRshbz9.Checked = ift.RenShenHeBingZheng.Split('#')[8].Equals("1");
                    chkRshbz10.Checked = ift.RenShenHeBingZheng.Split('#')[9].Equals("1");
                    chkRshbz11.Checked = ift.RenShenHeBingZheng.Split('#')[10].Equals("1");
                    chkRshbz12.Checked = ift.RenShenHeBingZheng.Split('#')[11].Equals("1");
                    chkRshbz13.Checked = ift.RenShenHeBingZheng.Split('#')[12].Equals("1");
                    chkRshbz14.Checked = ift.RenShenHeBingZheng.Split('#')[13].Equals("1");
                    chkRshbz15.Checked = ift.RenShenHeBingZheng.Split('#')[14].Equals("1");
                    chkRshbz16.Checked = ift.RenShenHeBingZheng.Split('#')[15].Equals("1");
                    chkRshbz17.Checked = ift.RenShenHeBingZheng.Split('#')[16].Equals("1");
                    chkRshbz18.Checked = ift.RenShenHeBingZheng.Split('#')[17].Equals("1");
                    chkRshbz19.Checked = ift.RenShenHeBingZheng.Split('#')[18].Equals("1");
                    if (ift.RenShenHeBingZheng.Split('#').Length >= 20)
                    {
                        chkRshbz20.Checked = ift.RenShenHeBingZheng.Split('#')[19].Equals("1");
                    }
                }
                txtQitaNwkJb.Visible = chkRshbz20.Checked;
                txtQitaNwkJb.Text = ift.QiTaNeiWaiKeJiBing;
                if (!string.IsNullOrEmpty(ift.BingFaZhengChks))
                {
                    chkBingfaZheng1.Checked = ift.BingFaZhengChks.Split('#')[0].Equals("1");
                    chkBingfaZheng2.Checked = ift.BingFaZhengChks.Split('#')[1].Equals("1");
                    chkBingfaZheng3.Checked = ift.BingFaZhengChks.Split('#')[2].Equals("1");
                    chkBingfaZheng4.Checked = ift.BingFaZhengChks.Split('#')[3].Equals("1");
                    chkBingfaZheng5.Checked = ift.BingFaZhengChks.Split('#')[4].Equals("1");
                    chkBingfaZheng6.Checked = ift.BingFaZhengChks.Split('#')[5].Equals("1");
                    chkBingfaZheng7.Checked = ift.BingFaZhengChks.Split('#')[6].Equals("1");
                    chkBingfaZheng8.Checked = ift.BingFaZhengChks.Split('#')[7].Equals("1");
                    chkBingfaZheng9.Checked = ift.BingFaZhengChks.Split('#')[8].Equals("1");
                    chkBingfaZheng10.Checked = ift.BingFaZhengChks.Split('#')[9].Equals("1");
                    chkBingfaZheng11.Checked = ift.BingFaZhengChks.Split('#')[10].Equals("1");
                    chkBingfaZheng12.Checked = ift.BingFaZhengChks.Split('#')[11].Equals("1");
                    chkBingfaZheng13.Checked = ift.BingFaZhengChks.Split('#')[12].Equals("1");
                    chkBingfaZheng14.Checked = ift.BingFaZhengChks.Split('#')[13].Equals("1");
                    chkBingfaZheng15.Checked = ift.BingFaZhengChks.Split('#')[14].Equals("1");
                    if (ift.BingFaZhengChks.Split('#').Length >= 16)
                    {
                        chkBingfaZheng16.Checked = ift.BingFaZhengChks.Split('#')[15].Equals("1");
                    }
                    if (ift.BingFaZhengChks.Split('#').Length >= 17)
                    {
                        chkBingfaZheng17.Checked = ift.BingFaZhengChks.Split('#')[16].Equals("1");
                        chkBingfaZheng18.Checked = ift.BingFaZhengChks.Split('#')[17].Equals("1");
                        chkBingfaZheng19.Checked = ift.BingFaZhengChks.Split('#')[18].Equals("1");
                        chkBingfaZheng20.Checked = ift.BingFaZhengChks.Split('#')[19].Equals("1");

                        chkBingfaZheng21.Checked = ift.BingFaZhengChks.Split('#')[20].Equals("1");
                        chkBingfaZheng22.Checked = ift.BingFaZhengChks.Split('#')[21].Equals("1");
                        chkBingfaZheng23.Checked = ift.BingFaZhengChks.Split('#')[22].Equals("1");
                        chkBingfaZheng24.Checked = ift.BingFaZhengChks.Split('#')[23].Equals("1");
                    }

                }
                txtBingFaZheng.Visible = chkBingfaZheng16.Checked;
                txtBingFaZheng.Text = ift.BingFaZheng;
                ddlHBsAg.Text = ift.HBsAg;
                rdosZaoPoShui.EditValue = ift.ZaoPoShui;
                ddlYangShui.Text = ift.YangShui;
                rdosGanRan.EditValue = ift.GanRan;
                rdosZhiChan.EditValue = ift.ZhiChan;
                txtZhiChanText.Visible = rdosZhiChan.SelectedIndex == 1;
                txtZhiChanText.EditValue = ift.ZhiChanText;
                rdosTaiPanYiChang.EditValue = ift.TaiPanYiChang;
                rdosTERGNJP.EditValue = ift.TaiErGongNeiJiongPo;
                txtTergnjpText.Visible = rdosTERGNJP.SelectedIndex == 1;
                txtTergnjpText.Text = ift.TaiErGongNeiJiongPoText;
                rdosQiDaiYiChang.EditValue = ift.QiDaiYiChang;
                txtKaiNaiShiJian.Text = ift.KaiNaiShiJian;

                //txtMfzxinLv1.Text = ift.MeiFenZhongXinLv1;
                //txtMfzxinLv2.Text = ift.MeiFenZhongXinLv2;
                //txtMfzxinLv3.Text = ift.MeiFenZhongXinLv3;
                txtMfzxinLv4.Text = ift.MeiFenZhongXinLv4;
                txtMfzxinLv5.Text = ift.MeiFenZhongXinLv5;
                txtMfzxinLv6.Text = ift.MeiFenZhongXinLv6;

                //txtHuxi1.Text = ift.HuXi1;
                //txtHuxi2.Text = ift.HuXi2;
                //txtHuxi3.Text = ift.HuXi3;
                txtHuxi4.Text = ift.HuXi4;
                txtHuxi5.Text = ift.HuXi5;
                txtHuxi6.Text = ift.HuXi6;

                //txtJiZhangLi1.Text = ift.JiZhangLi1;
                //txtJiZhangLi2.Text = ift.JiZhangLi2;
                //txtJiZhangLi3.Text = ift.JiZhangLi3;
                txtJiZhangLi4.Text = ift.JiZhangLi4;
                txtJiZhangLi5.Text = ift.JiZhangLi5;
                txtJiZhangLi6.Text = ift.JiZhangLi6;

                //txtHouFanShe1.Text = ift.HouFanShe1;
                //txtHouFanShe2.Text = ift.HouFanShe2;
                //txtHouFanShe3.Text = ift.HouFanShe3;
                txtHouFanShe4.Text = ift.HouFanShe4;
                txtHouFanShe5.Text = ift.HouFanShe5;
                txtHouFanShe6.Text = ift.HouFanShe6;

                //txtPiFuYanSe1.Text = ift.PiFuYanSe1;
                //txtPiFuYanSe2.Text = ift.PiFuYanSe2;
                //txtPiFuYanSe3.Text = ift.PiFuYanSe3;
                txtPiFuYanSe4.Text = ift.PiFuYanSe4;
                txtPiFuYanSe5.Text = ift.PiFuYanSe5;
                txtPiFuYanSe6.Text = ift.PiFuYanSe6;

                //txtZongPingFenShu1.Text = ift.ZongPingFenShu1;
                //txtZongPingFenShu2.Text = ift.ZongPingFenShu2;
                //txtZongPingFenShu3.Text = ift.ZongPingFenShu3;
                txtZongPingFenShu4.Text = ift.ZongPingFenShu4;
                txtZongPingFenShu5.Text = ift.ZongPingFenShu5;
                txtZongPingFenShu6.Text = ift.ZongPingFenShu6;
                txtJieShengZhe.Text = ift.JieShengZhe;
                txtDianYanZhe.Text = ift.DianYanZhe;
                LoginUser.UserId = ift.DianYanZheId;

                //以下医生字段 只读不存
                textEdit_TiWen.Text = ift.TiGe_TiWen;
                textEdit_HuXi.Text = ift.TiGe_HuXi;
                textEdit_XinLv.Text = ift.TiGe_XinLv;
                textEdit_KuSheng.Text = ift.TiGe_KuSheng;
                textEdit_LianSe.Text = ift.TiGe_LianSe;
                textEdit_YanSe.Text = ift.TiGe_YanSe;
                textEdit_ChuXueDian.Text = ift.TiGe_ChuXueDian;
                textEdit_YingPi.Text = ift.TiGe_YingPi;
                textEdit_ShuiZhong.Text = ift.TiGe_ShuiZhong;
                textEdit_TuoPi.Text = ift.TiGe_TuoPi;
                textEdit_ChanLiu.Text = ift.TiGe_ChanLiu;
                textEdit_XueZhong.Text = ift.TiGe_XueZhong;
                textEdit_KouQaing.Text = ift.TiGe_KouQiang;
                textEdit_X_WaiXing.Text = ift.TiGe_X_WaiXing;
                textEdit_X_Xin.Text = ift.TiGe_X_Xin;
                textEdit_X_Fei.Text = ift.TiGe_X_Fei;
                textEdit_F_WaiXing.Text = ift.TiGe_X_WaiXing;
                textEdit_F_Gan.Text = ift.TiGe_F_Gan;
                textEdit_F_Pi.Text = ift.TiGe_F_Pi;
                textEdit_F_QiDai.Text = ift.TiGe_F_QiDai;
                textEdit_SiZhiZhangLi.Text = ift.TiGe_SiZhiZhangLi;
                textEdit_FanShe.Text = ift.TiGe_MOrO;
                textEdit_GanMen.Text = ift.TiGe_GangMen;
                textEdit_WaiShengZhiQi.Text = ift.TiGe_WaiShengZhiQi;
                textEdit_JiXing.Text = ift.TiGe_JiXing;
                textEdit_ChuBuYinXiang.Text = ift.TiGe_ChuBuYinXiang;
                textEdit_JianChaZhe.Text = ift.TiGe_JianChaZhe;
                memoEdit_ZhiLiaoJingGuo.Text = ift.TiGe_ZhiLiaoJingGuo;
                textEdit_YiSheng.Text = ift.TiGe_ZhiLiaoJingGuo_YiSheng;
                textEdit_C_Xin.Text = ift.TiGe_ChuYuan_Xin;
                textEdit_C_Fei.Text = ift.TiGe_ChuYuan_Fei;
                textEdit_C_Gan.Text = ift.TiGe_ChuYuan_Gan;
                textEdit_C_Pi.Text = ift.TiGe_ChuYuan_Pi;
                textEdit_C_Qi.Text = ift.TiGe_ChuYuan_Qi;
                textEdit_C_QiTa.Text = ift.TiGe_ChuYuan_QiTa;
                textEdit_ChuYuanZhenDuan.Text = ift.TiGe_ChuYuanZhenDuan;
                textEdit_ZhiLiaoZhuanGui.Text = ift.TiGe_ZhiLiaoZhuanGui;
                textEdit_ChuYuanYiZhu.Text = ift.TiGe_ChuYuanYiZhu;
                txt_CHuYaunRiQi.Text = ift.TiGe_ChuYuanRiQi;


            }
            else if (ret.Code == 2)
            {
                this.Id = string.Empty;
                return;
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }


        #region 设置 enter键当做Tab切换
        /// <summary>
        /// 设置 enter键当做Tab切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void TemperatureEdit1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                SendKeys.SendWait("{Tab}");
            }
        }
        #endregion

        private void BtnReData_Click(object sender, EventArgs e)
        {
            BindInfo(this.Id);
        }

        private void BtnCls_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定清空所有输入框吗？", "提示",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) return;
            string sign = txtDianYanZhe.Text;
            foreach (var c in groupControl1.Controls)
            {
                if (c is TextEdit)
                    ((TextEdit)c).Text = string.Empty;
                if (c is ComboBoxEdit)
                    ((ComboBoxEdit)c).SelectedIndex = -1;
                if (c is CheckEdit)
                    ((CheckEdit)c).Checked = false;
                if (c is DateEdit)
                    ((DateEdit)c).Text = string.Empty;
                if (c is RadioGroup)
                    ((RadioGroup)c).SelectedIndex = -1;
            }
            foreach (var c in groupControl2.Controls)
            {
                if (c is TextEdit && !((TextEdit)c).Properties.ReadOnly)
                    ((TextEdit)c).Text = string.Empty;
            }
            txtDianYanZhe.Text = sign;
        }
    }
}